<template>
  <!-- 新增一个 div 用于包裹搜索框 -->
  <div class="search-container">
    <a-input-search class="search" placeholder="输入内容以搜索" search-button @search="search"/>
  </div>
  <PostList
      :total="total"
      :data="data"
      :editable="true"
      @get-data="getData"
  >
  </PostList>
</template>

<script setup>
import { ref } from "vue";
import PostList from "@/components/PostList.vue";
import {listPostVOByPageUsingPost} from "@/api/PostRequest";

let postType = ref('adminList');
let searchContent = ref('');

function search(content) {
  if(content === ''){
    postType.value = "adminList";
  }else{
    postType.value = "searchList";
    searchContent.value = content;
  }
}

const data = ref([]);
const total = ref(0);

async function getData(current, pageSize) {
  const result = await listPostVOByPageUsingPost({
    current: current,
    pageSize: pageSize,
    sortField: 'createTime',
    sortOrder: 'descend',
  });
  data.value = result.data.data.records;
  total.value = result.data.data.total;
}
</script>

<style scoped>
/* 搜索框样式 */
.search {
  width: 360px;
}

/* 搜索框容器样式 */
.search-container {
  display: flex;
  justify-content: center;
  margin-bottom: 20px;
}
</style>